package com.zhz.mall.common.annotation;

import cn.hutool.core.date.DatePattern;
import com.zhz.mall.common.constraints.DateFormatValidator;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * 日期工具类
 * @author zhouhengzhe
 */
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RUNTIME)
@Repeatable(DateFormat.List.class)
@Documented
@Constraint(validatedBy = DateFormatValidator.class)
public @interface DateFormat {

    String message() default "{com.ygp.its.infrastructure.utils.validation.constraints.DateFormat}";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    String pattern() default DatePattern.NORM_DATE_PATTERN;

    @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
    @Retention(RUNTIME)
    @Documented
    @interface List {

        DateFormat[] value();
    }
}
